package libs

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"strings"
)

func GetBearerToken(c *gin.Context) (string, error) {
	header := c.GetHeader("Authorization")
	if header == "" {
		return "", fmt.Errorf("没有提供没有提供鉴权Token: Bearer")
	}
	split := strings.Split(header, "Bearer ")
	if len(split) != 2 {
		return "", fmt.Errorf("没有提供鉴权Token: Bearer")
	}
	token := split[1]
	if len(token) == 0 {
		return "", fmt.Errorf("没有提供鉴权Token: Bearer")
	}
	return token, nil
}
